Add type annotations to cqlengine models and query modules#721
Draft
dkropachev wants to merge 1 commit intomasterfrom
Draft
Add type annotations to cqlengine models and query modules#721dkropachev wants to merge 1 commit intomasterfrom
dkropachev wants to merge 1 commit intomasterfrom
Conversation
Based on VincentRPS/python-driver#fix-engine-typing with fixes: - Add `from __future__ import annotations` to both files - Fix `__ne__` infinite recursion bug (`not (self != q)` -> `not (self == q)`) - Fix `all()` and `filter()` return types to return `ModelQuerySet` not `list` - Drop incorrect `__getitem__` override on BaseModel (would break column access) - Drop wrong `objects: query.ModelQuerySet` annotation (it's a descriptor) - Drop unused `T = TypeVar` with forward reference issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Based on https://github.com/VincentRPS/python-driver/tree/fix-engine-typing with the following fixes applied:
from __future__ import annotationsto bothmodels.pyandquery.py(the original PR only added it toquery.pybut usedfloat | None/list[M]syntax inmodels.py)AbstractQuerySet.__ne__infinite recursion bug:return not (self != q)→return not (self == q)all()andfilter()return types toModelQuerySetinstead oflist[M](they return querysets, not lists)BaseModel.__getitem__(slice | int)that would override the existing column-access__getitem__(str)and break itobjects: query.ModelQuerySettype annotation (attribute is aQuerySetDescriptor, not aModelQuerySet)T = TypeVar('T', bound=ModelQuerySet)that had a forward reference issueTest plan
uv run pytest tests/unit/cqlengine/passes (13/13)